<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php echo (C("cfg_webname")); ?></title>
    <link href="/Application/Admin/Public/css/base.css" rel="stylesheet">
    <link href="/Application/Admin/Public/css/school.css" rel="stylesheet">
    <link rel="stylesheet" href="/Application/Admin/Public/custom/uimaker/easyui.css">
    <link rel="stylesheet" type="text/css" href="/Application/Admin/Public/custom/uimaker/icon.css">
    <style>
    #formAdd table{ width:100%;}
    #formAdd table td{ padding:5px;}
    #formAdd table td.td-left{text-align: right; padding-right: 10px;}
    </style>

</head>
<body>
<div class="container">
    <table id="dg"></table>
</div>

<div class="container">

    <table id="cxdm"></table>

    <!-- 操作条 -->
    <div id="tb" style="padding:0 30px;">
        <div id="toolbar">
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" onclick ="addComputer()">新增</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" onclick="editComputer()">修改</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" onclick="delComputer()">删除</a>
            <input id="searchcont" name="search" value="" placeholder="请输入.."></input>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="searchComputer()">搜索</a><hr style="border: 1px solid #ddd;" />
        </div>
    </div>


    <!-- 增加修改服务器 -->
    <div id="DivAdd" class="easyui-dialog" style="width:450px;height:450px;padding:10px 20px" closed="true" resizable="true" modal="true" data-options="iconCls: 'icon-add',buttons: '#dlg-buttons'">
        <form id="formAdd" method="post" novalidate="novalidate">
            <input type="hidden" id="action" name="action">
            <input type="hidden" id="id" name="computerid">
            <table>
                <tr>
                    <td class="td-left" width="25%">服务器名称:</td>
                    <td width="75%"><input class="easyui-textbox" type="text" name="title" data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">CPU:</td>
                    <td><input class="easyui-textbox" type="text" name="cpu" data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">内存:</td>
                    <td><input class="easyui-textbox" type="text" name="ram" data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">硬盘大小:</td>
                    <td><input class="easyui-textbox" type="text" name="harddisk" data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">备注:</td>
                    <td><input class="easyui-textbox" type="text" name="description" data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">系统:</td>
                    <td><input class="easyui-textbox" type="text" name="system" data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">带宽:</td>
                    <td><input class="easyui-textbox" type="text" name="bandwidth" data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">排序:</td>
                    <td><input class="easyui-numberspinner" value="1" name="orderid" data-options="increment:1,required:true" style="height:30px;"></td>
                </tr>

                
              </table>
        </form>
    </div>
    <div id="dlg-buttons">
        <div style="text-align:right;">
            <a href="javascript:void(0)" class="easyui-linkbutton" id="btnAddOK" iconcls="icon-ok" onclick="btnAddOK()">确定</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#DivAdd').dialog('close')">关闭</a>
        </div>
    </div>


</div>

<script type="text/javascript" src="/Application/Admin/Public/custom/jquery.min.js"></script>
<script type="text/javascript" src="/Application/Admin/Public/custom/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/Application/Admin/Public/custom/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
    $(function(){
        index();
    });

    function index(){
        //加载数据
        var search = $('#searchcont').val();
        $('#cxdm').datagrid({
            title:'服务器列表',
            width:'100%',
            height:$(window).height(),
            fitColumns:true,
            striped: true,
            checkOnSelect:true,
            singleSelect : true,
            queryParams:{
                computer:search
            },
            frozenColumns:[[//在冻结列中加入多选框
                {field:'chek',checkbox:true}
            ]],
            url:'<?php echo U("Computer/computerList");?>',
            loadMsg:'数据加载中请稍后……',
            pagination: false,
            rownumbers: false,
            pageSize:10,
            toolbar:'#tb',
            columns:[[
                {field:'computerid',title: '服务器ID',align: 'center',sortable:"true",width:50},
                {field:'title',title: '服务器名称',align: 'center',width:100,},
                {field:'cpu',title: 'CPU',align: 'center',width:100},
                {field:'ram',title: '内存',align: 'center',width:100},
                {field:'harddisk',title: '硬盘大小',align: 'center',width:100},
                {field:'description',title: '备注',align: 'center',width:100},
                {field:'system',title: '系统',align: 'center',width:100},
                {field:'bandwidth',title: '带宽',align: 'center',width:100},
                {field:'admin',title: '操作人',align: 'center',width:50,hidden:"ture"},
                {field:'orderid',title: '排序',align: 'center',width:50},
                {field:'createtime',title: '创建时间',align: 'center',width:100,hidden:"ture"},
                {field:'updatetime',title: '修改时间',align: 'center',width:100,hidden:"ture"},
                {field:'id',title: 'ID',align: 'center',width:100,hidden:'ture'},
            ]],
        });
    }

    function addComputer(){
        $("#DivAdd").dialog('open').dialog('setTitle', '新增服务器');
        $('#formAdd').form('clear');
        $('#action').val("add");
    }

    function editComputer(){
        var arr=$('#cxdm').datagrid('getSelections');
        if(!arr[0]){
            $.messager.alert('提示','请选择一条数据!');
            return false;
        }
        $("#DivAdd").dialog('open').dialog('setTitle', '修改服务器');
        $('#formAdd').form('load',arr[0]);
        $('#action').val("update");
    }

    function searchComputer(){
        index();
    }

    function delComputer(){
        var arr=$('#cxdm').datagrid('getSelections');
        var cc = arr[0];

        if(!cc){
            $.messager.alert('提示','请选择一条数据!');
            return false;
        }
        $.messager.confirm('提示', '确定删除?', function(r){
            if (r){
               var computerid = cc.computerid;
               $.ajax({
                    url:'<?php echo U("Computer/delComputer");?>',
                    data:{
                        computerid:computerid,
                    },
                    success:function(result){
                        if (result.sta==1){
                            $.messager.alert('提示','删除成功!','info',function(){
                                reload();
                            });
                        } else {
                            $.messager.show({
                                title: '错误提示',
                                msg: result.msg
                            });
                        }
                    }
               })
            }
        });
    }


    function reload(){
        window.location.reload();
    }

    function btnAddOK() {
        $('#formAdd').form('submit',{
            url: '<?php echo U("Computer/addComputer");?>',
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = eval('('+result+')');
                if (result.success){
                    if(!result.id){
                        $.messager.confirm('提示', '添加成功，继续添加?', function(r){
                            if (r){
                                $('#formAdd').form('clear');
                            }else{
                                reload();
                            }
                        });
                    }else{
                        $.messager.alert('提示','修改成功!','info',function(){
                            reload();
                        });
                    }
                } else {
                    $.messager.show({
                        title: '错误提示',
                        msg: result.msg
                    });
                }
            }
        });
    }

</script>

</body>
</html>